package com.cloudcc.mobile.view.aduit.presenter.impl;



import com.cloudcc.mobile.basebean.BaseListEntity;
import com.cloudcc.mobile.view.aduit.bean.assetsBean;
import com.cloudcc.mobile.view.aduit.bean.shopBean;
import com.cloudcc.mobile.view.aduit.model.IAduitNearByModel;
import com.cloudcc.mobile.view.aduit.presenter.IAduitNearByPresenter;
import com.cloudcc.mobile.view.aduit.view.IAduitNearByView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * <pre>
 *     author : 92152
 *     e-mail : xxx@xx
 *     time   : 2019/12/04
 *     desc   :
 *     version: 1.0
 * </pre>
 */
public class AduitNearByPresenter implements IAduitNearByPresenter {
    private IAduitNearByView view;
    private IAduitNearByModel model;

    public AduitNearByPresenter(IAduitNearByView view, IAduitNearByModel model) {
        this.view = view;
        this.model = model;
    }

    @Override
    public void inquireShopData(Map<String, String> praise) {
        view.showDialog(true);
        model.inquireShopData(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseListEntity<shopBean>>() {
                    @Override
                    public void onCompleted() {
                        view.showDialog(false);
                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("获取数据失败:"+e.getMessage());
                        view.showDialog(false);
                        view.inquireShopData(null);
                    }

                    @Override
                    public void onNext(BaseListEntity<shopBean> bean) {
                        view.inquireShopData(bean);
                    }
                });
    }

    @Override
    public void inquireAssetsData(Map<String, String> praise) {
        view.showDialog(true);
        model.inquireAssetsData(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseListEntity<assetsBean>>() {
                    @Override
                    public void onCompleted() {
                        view.showDialog(false);
                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("获取数据失败:"+e.getMessage());
                        view.showDialog(false);
                        view.inquireAssetsData(null);
                    }

                    @Override
                    public void onNext(BaseListEntity<assetsBean> bean) {
                        view.inquireAssetsData(bean);
                    }
                });
    }
}
